<?php

class DefaultController extends BaseAdminController {

    public $pageTitle = 'Sopha Admin';
    public $layout = "column1";

    /**
     * @return array action filters
     */
    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules() {
        return array(
            array('allow', // allow admin user to perform all actions
                'actions' => array('index', 'login', 'logout'),
                'users' => array(User::model()->getAdmin()->email),
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }

    public function actionIndex() {
        //$this->render('index');
        //Redirect to product page 
        
        $this->redirect(Yii::app()->request->baseUrl . '/admin/product');
    }

    public function actionLogin() {
        $model = new LoginForm;
        if (isset($_POST['LoginForm'])) {
            // collects user input data
            $model->attributes = $_POST['LoginForm'];
            // validates user input and redirect to previous page if validated
            if ($model->validate())
                $this->redirect(Yii::app()->user->returnUrl);
        }
        // displays the login form
        $this->render('login', array('model' => $model));
    }

    /**
     * Logs out the current user and redirect to homepage.
     */
    public function actionLogout() {
        Yii::app()->user->logout();
        $this->redirect(Yii::app()->homeUrl);
    }

}
